//
//  DBHelper+Reader.h
//  KidReading
//
//  Created by Telen on 16/4/10.
//  Copyright © 2016年 刘赞黄Telen. All rights reserved.
//

#import "DBHelper.h"
#import "DBKeyDefine.h"

#define TBKey_Parts @"parts"
#define TBKey_BeforeParts   @"beforeParts"
#define TBKey_AfterParts    @"afterParts"
#define TBKey_SortMark  @"sort_mark"

typedef long long LongLong;

@interface TABLE_BOOK_Base : TABLE_base
@property(nonatomic,strong)NSString* itemType;
@property(nonatomic,assign)NSInteger itemId;
@property(nonatomic,strong)id infoDefine;
@property(nonatomic,assign)bookshelf_saleFlag_type freeflag;
@property(nonatomic,assign)BOOL newflag;
@property(nonatomic,assign)LongLong rCount;//热门
@property(nonatomic,strong)NSString* name_pinyin;
@property(nonatomic,strong)NSDictionary* payStyle;
@property(nonatomic,assign)LongLong lastModifyDate;//我的最近阅读记录
@property(nonatomic,strong)NSString* readSource;
@property(nonatomic,strong)NSDictionary* showInfo;
@property(nonatomic,assign)NSInteger readingFinished;
@end
@interface TABLE_BOOKS : TABLE_BOOK_Base
@property(nonatomic,assign)NSInteger bookId;
@property(nonatomic,assign)NSInteger originalId;
@property(nonatomic,strong)NSString* name_zh;
@property(nonatomic,strong)NSString* name_en;
@property(nonatomic,strong)NSString* thumb;
@property(nonatomic,strong)NSString* parts;
@property(nonatomic,strong)NSString* beforeParts;
@property(nonatomic,strong)NSString* afterParts;
@property(nonatomic,assign)LongLong createdDate;
@property(nonatomic,assign)LongLong edition;
@property(nonatomic,assign)LongLong partsEdition;
@property(nonatomic,assign)NSInteger pageNums;
@property(nonatomic,strong)NSString* voiceUrl;
- (NSArray *)partsArr;
- (NSArray *)beforePartsArr;
- (NSArray *)afterPartArr;
- (NSDictionary *)listInfo;
@end


@interface TABLE_SUPPORT_FILE : TABLE_base
@property(nonatomic,strong)NSString* sfKey;
@property(nonatomic,strong)NSString* sfUri;
@property(nonatomic,assign)LongLong edition;
@property(nonatomic,strong)NSString* countryCode;
@end


@interface TABLE_TIMESTAMP_LAST : TABLE_base
@property(nonatomic,assign)NSString* name;
@property(nonatomic,assign)LongLong time;
@end
@interface TABLE_TIMESTAMP : TABLE_base
@property(nonatomic,assign)NSInteger userId;
@property(nonatomic,assign)LongLong book;
@property(nonatomic,assign)LongLong support_file;
@property(nonatomic,assign)LongLong notice;
@property(nonatomic,assign)LongLong quiz;
@property(nonatomic,assign)LongLong talk_list;
@property(nonatomic,assign)LongLong talk_video_list;
@property(nonatomic,assign)LongLong readingCount;
@end

@interface TABLE_NOTICE : TABLE_base
@property(nonatomic,assign)NSInteger noticeId;
@property(nonatomic,assign)NSInteger noticeType;
@property(nonatomic,strong)NSString* noticeMemo;
@property(nonatomic,strong)NSString* noticeContent;
@end

@interface TABLE_QUIZ : TABLE_base
@property(nonatomic,assign)NSInteger bookId;
@property(nonatomic,strong)NSString* quizUri;
@property(nonatomic,assign)LongLong edition;
@end

//talk
@interface TABLE_TALK_LIST : TABLE_base
@property(nonatomic,assign)NSInteger talkId;
@property(nonatomic,strong)NSString* talkZipUrl;
@property(nonatomic,assign)LongLong edition;
@end

@interface TABLE_TALK_VEDIO_LIST : TABLE_base
@property(nonatomic,assign)NSInteger videoId;
@property(nonatomic,assign)NSString* videoUrl;
@property(nonatomic,assign)LongLong edition;
@end

//热门
@interface TABLE_READING_COUNT : TABLE_base
@property(nonatomic,assign)NSInteger bookId;
@property(nonatomic,assign)LongLong rCount;
@end

#pragma mark
@interface DBHelper (Reader)
@property(nonatomic,strong)JRFMDatabaseQueue* dbQue;
@property(nonatomic,assign)BOOL isLimitedTimeForNet; //end From notice 是否受时间限制
@property(nonatomic,strong)TABLE_TIMESTAMP_LAST* tb_lastTime;
@property(nonatomic,assign)BOOL isSpotlightClear;    //记录是否清空了 系统搜索缓存

- (void)readerDB_getList:(void(^)(NSArray* list))retlist fromTableClass:(NSString*)tableClassName where:(NSString*)wheresql;
- (void)readerDB_getDictList:(void(^)(NSArray* list))retlist fromTableClass:(NSString*)tableClassName where:(NSString*)wheresql;

- (void)readerDB_updateListToTableClass:(NSString *)tableClassName dictArr:(NSArray*)dictList complete:(void (^)(void))comp;
- (void)readerDB_deletListToTableClass:(NSString *)tableClassName dictArr:(NSArray*)dictList complete:(void (^)(void))comp;
- (void)readerDB_deletListToTableClass:(NSString *)tableClassName tbArr:(NSArray*)dictList complete:(void (^)(void))comp;

- (void)readerDB_inQueue_executeUpdate:(NSString*)str complete:(void (^)(void))comp;
- (void)readerDB:(void (^)(JRFMDatabase *))dbDo;
- (void)readerDB_countForTableName:(NSString *)tableClassName where:(NSString*)where complete:(void(^)(NSInteger))comp;
- (void)readerDB_maxForTableName:(NSString *)tableClassName key:(NSString*)key where:(NSString*)where complete:(void(^)(LongLong))comp;
- (void)readerDB_minForTableName:(NSString *)tableClassName key:(NSString*)key where:(NSString*)where complete:(void(^)(LongLong))comp;


@end
